﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Camc.OutsourceProcession.Configuration;
using Camc.OutsourceProcession.Web;

namespace Camc.OutsourceProcession.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class SCDContextFactory : IDesignTimeDbContextFactory<SCDDbContext>
    {
        public SCDDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<SCDDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            //通过configuration无法读取配置参数
            //SCDDbContextOptionsConfigurer.Configure(builder, "Server=101.200.80.158; Database=OutsourceProcessionDb; Uid=sa;Pwd=tjhj123456,");
            SCDDbContextOptionsConfigurer.Configure(builder,
                configuration.GetConnectionString(OutsourceProcessionConsts.SecondDbConnectionStringName));

            return new SCDDbContext(builder.Options);
        }

	}
}